import { _decorator, sys } from 'cc';
import { BCProjectDefines } from '../../utils/BCProjectDefines';
import { BCAndroidMgr } from './BCAndroidMgr';
import { BCIOSMgr } from './BCIOSMgr';
import { BCPlatformInterface } from './BCPlatformInterface';
import { BCSimulatorMgr } from './BCSimulatorMgr';

/**
 * Predefined variables
 * Name = BCPlatformMgr
 * DateTime = Fri Dec 31 2021 17:59:18 GMT+0800 (中国标准时间)
 * Author = 风流鼻涕淌
 * FileBasename = BCPlatformMgr.ts
 * FileBasenameNoExtension = BCPlatformMgr
 * URL = db://assets/Main/script/Controller/platform/BCPlatformMgr.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
export class BCPlatformMgr {
	private static m_instance: BCPlatformMgr = null;

	private m_platformActions: BCPlatformInterface = null;

	private constructor() {
		if (globalThis.CC_PREVIEW){
			this.m_platformActions = new BCSimulatorMgr();
		} else {
			switch (sys.os) {
				case sys.OS.IOS:
					this.m_platformActions = new BCIOSMgr();
					break;
				case sys.OS.ANDROID:
					this.m_platformActions = new BCAndroidMgr();
					break;
			}
		}
	}

	static get instance() {
		if (!this.m_instance) {
			this.m_instance = new BCPlatformMgr();
		}
		return this.m_instance;
	}

	setScreenOrientation(orientation: BCProjectDefines.ScreenOrientation) {
		this.m_platformActions.setScreenOrientation(orientation);
	}

	getDeviceId(): string {
		return this.m_platformActions.getDeviceId();
	}

	getAppVersion(): string {
		return this.m_platformActions.getAppVersion();
	}

	showToast(toast: string){
		this.m_platformActions.showToast(toast);
	}

	copy(text: string){
		this.m_platformActions.copy(text);
	}

	sendEvent(eventName: string, params?: Map<string, any>) {
		this.m_platformActions.sendEvent(eventName, params);
	}

	vibrate(duration: number){
		this.m_platformActions.vibrate(duration);
	}
}
